/***************************************************************************
 *  Filename: programmanager.h
 *  Class: ProgramManager
 *
 *  Copyright 2012  Xander van Kooten
 *  <xandervk@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *
 ****************************************************************************/

/*
 *
 * This file is part of Parsax-Remote-Controller.
 *
 *    Parsax-Remote-Controller is free software: you can redistribute it
 *    and/or modify it under the terms of the GNU General Public License
 *    as published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    Parsax-Remote-Controller is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Parsax-Remote-Controller.
 *    If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef PROGRAMMANAGER_H
#define PROGRAMMANAGER_H

#include <QObject>
#include <slavecommunicator.h>
#include <messageparser.h>
#include "processmanager.h"

/*!
 \brief The ProgramManager is responsible for monitoring multiple
 processes.

 The program manager starts/stops existent ProcessManager objects, and also
 create new ones on request from the master. This function handles the
 communication between all the processes and the master on both directions.

*/
class ProgramManager : public QObject
{
    Q_OBJECT
public:
    /*!
     \brief Object Constructor.

     \param parent
    */
    explicit ProgramManager(QObject *parent = 0);
    
signals:

public slots:

private:
    MessageParser *parser; /*!< Interpret the messages */
    SlaveCommunicator *communicationHandler; /*!< Handle the communication with the master */
    QMap<QString, ProcessManager*> processesManager; /*!< List of processes running on this slave */

private slots:

    /*!
     \brief Starts a program if it exists in the current list of processes.

     \param id Id of the program to be started.
    */
    void startProgram(QString id);

    /*!
     \brief Starts a new program.

     \param id Id for the new program.
     \param program Program to be executed.
     \param params Startup arguments.

     If the id doesn't exist, a new process manager is created and started. If the id
     already exists, nothing is done.
    */
    void startProgram(QString id, QString program, QStringList params);

    /*!
     \brief Stops an existing program

     \param id Id of the program to be stopped.
    */
    void stopProgram(QString id);

    /*!
     \brief Restarts an existing program.

     \param id Id of the program to be restarted.
    */
    void restartProgram(QString id);

    /*!
     \brief Send the status of a program to the master.

     \param id Id of the program.
     \param status Status of the program.
    */
    void sendProgramStatus(QString id, QString status);

    void sendAllStatus();
    /*!
     \brief Send command line output from a program to the master.

     \param id Id of the program.
     \param type Type output.
     \param msg The message.
    */
    void sendProgramClo(QString id, int type, QString msg);

    /*!
     \brief

     \param id
     \param cmd
    */
    void sendCmdToProgram(QString id, QString cmd);
};

#endif // PROGRAMMANAGER_H
